home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / programs / lora210e.zip / STRUCT.ZIP / READSYS.C < prev    next >
C/C++ Source or Header  |  1992-04-07  |  2KB  |  90 lines

  1. /*
  2.                           Lora-CBIS Ver. 2.00
  3.  
  4.              Copyright (c) 1989, 1990, 1991 by Marco Maccaferri.
  5.                           All rights reserved.
  6.  
  7.  
  8.                           Source code examples
  9.                      System record read reoutines
  10.  
  11.  
  12.   You may use this structures at your own risk. The author cannot guarantee
  13.   that this structures are maintained in all future versions of the program.
  14.   You can freely (and you are encouraged on that) distribute this file
  15.   without limitations.
  16.  
  17.   You can contact the autor at one of the following address:
  18.  
  19.   Marco Maccaferri
  20.   BBS: 39-51-6331730 (2:332/402)
  21.   BIX: marco.m
  22.  
  23. */
  24. #include <stdio.h>
  25. #include <io.h>
  26. #include <time.h>
  27. #include <fcntl.h>
  28.  
  29. #include "lora.h"
  30.  
  31. #define MSG_AREAS   200
  32.  
  33. int read_system(s, type)
  34. int s, type;
  35. {
  36.    int fd, nsys, i;
  37.    struct _sys_idx sysidx[MSG_AREAS];
  38.    struct _sys sys;
  39.  
  40.    if (type == 1)
  41.    {
  42.       fd = open("SYSMSG.IDX", O_RDONLY|O_BINARY);
  43.       if (fd == -1)
  44.          return (0);
  45.       nsys = read(fd, (char *)&sysidx, sizeof(struct _sys_idx) * MSG_AREAS);
  46.       nsys /= sizeof (struct _sys_idx);
  47.       close(fd);
  48.    }
  49.    else if (type == 2)
  50.    {
  51.       fd = open("SYSFILE.IDX", O_RDONLY|O_BINARY);
  52.       if (fd == -1)
  53.          return (0);
  54.       nsys = read(fd, (char *)&sysidx, sizeof(struct _sys_idx) * MSG_AREAS);
  55.       nsys /= sizeof (struct _sys_idx);
  56.       close(fd);
  57.    }
  58.  
  59.    for (i=0; i < nsys; i++)
  60.    {
  61.       if (sysidx[i].area == s)
  62.          break;
  63.    }
  64.  
  65.    if (i == nsys)
  66.       return (0);
  67.  
  68.    if (type == 1)
  69.    {
  70.       fd = open("SYSMSG.DAT", O_RDONLY|O_BINARY);
  71.       if (fd == -1)
  72.          return (0);
  73.       lseek (fd, (long)i * SIZEOF_MSGAREA, SEEK_SET);
  74.       read(fd, (char *)&sys.msg_name, SIZEOF_MSGAREA);
  75.       close(fd);
  76.    }
  77.    else if (type == 2)
  78.    {
  79.       fd = open("SYSFILE.DAT", O_RDONLY|O_BINARY);
  80.       if (fd == -1)
  81.          return (0);
  82.       lseek (fd, (long)i * SIZEOF_FILEAREA, SEEK_SET);
  83.       read(fd, (char *)&sys.file_name, SIZEOF_FILEAREA);
  84.       close(fd);
  85.    }
  86.  
  87.    return (1);
  88. }
  89.  
  90.